//
//  MainViewController.swift
//  Sina
//
//  Created by yuanyuan on 15/12/17.
//  Copyright © 2015年 yuanyuan. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

//    必选的属性
    let maintabBar = MainTabBar()
   
//    private func 是swift中函数的特殊声明形式，希望swift方法选择器和访问控制关键字能够兼容需要使用@objc
//    @objc private 要保证监听方法的安全性 并且可以响应点击事件的特殊写法
    
   @objc private func composeBtnDidClick() {
    
    print(__FUNCTION__)
    
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
//tabBar是只读属性 不能够进行直接设置可以使用kvc在运行时间接赋值
        print(tabBar.classForCoder)
        maintabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        setValue(maintabBar, forKey: "tabBar")
         //classForCoder 对象的类的字符串形式
        print(tabBar.classForCoder)
//        添加子视图控制器
        addChildViewControllers()
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
//    private只能在本类中访问
    private func addChildViewControllers() {
        
    addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
    addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProflieTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
        
    }
    
    private func addChildViewController(vc:UIViewController,title:String,imageName:String) {
        
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        self.addChildViewController(nav)
        
    }



}
